#ifndef HTTP_MU_H
#define HTTP_MU_H

#include "httpmu_port.h"

#ifdef __cplusplus
extern "C" {
#endif


#define HTTPMU_MAX_RETRIES 3
#define HTTPMU_MIN_RETRY_INTERVAL 0   // seconds
#define HTTPMU_MAX_RETRY_INTERVAL 10  // seconds
    
typedef struct {
    char *key;
    char *value;
}head_option_t;    
#define MAX_HEAD_ITEM 10

typedef struct {
    char *method;
    char *url;
    head_option_t options[MAX_HEAD_ITEM];
}http_head_t;


http_head_t *httpmu_create_head(const char *method, const char *url);
void httpmu_free_head(http_head_t *head);
int httpmu_set_option(http_head_t *head, const char *key, const char *val);
const char *httpmu_get_option(http_head_t *head, const char *key);

typedef struct {
    int socket;
}httpmu_c_t;

httpmu_c_t *httpmu_create_client(const char *group_ip, uint16_t port);
void httpmu_free_client(httpmu_c_t *client);
int httpmu_client_send_request(httpmu_c_t *client, http_head_t *head, const char *content);

#define HTTPMU_MAX_RESOURCE 3
typedef int (*request_handle_t)(http_head_t *request, const char *content, void *priv_data);
typedef struct {
    char method[10];
    request_handle_t handle;
    void *priv_data;
}request_resource_t;

typedef struct {
    int socket;
    request_resource_t request[HTTPMU_MAX_RESOURCE];
    httpmu_mutex_t request_mutex;
    httpmu_thread_t server_id;
    uint8_t is_stop;
}httpmu_s_t;

httpmu_s_t *httpmu_create_server(const char *ip, const uint16_t port);
void httpmu_free_server(httpmu_s_t *server);
int httpmu_start_server(httpmu_s_t *server);
int httpmu_stop_server(httpmu_s_t *server);
int httpmu_server_set_resource(httpmu_s_t *server, request_handle_t handle, const char *method, void *data);
int httpmu_server_del_resource(httpmu_s_t *server, request_handle_t handle); 



#ifdef __cplusplus
}
#endif

#endif
